package com.zjs.jsp.domain.axd;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.zjs.jsp.domain.jsp.Jsp_Items;
import com.zjs.jsp.domain.jsp.Jsp_Order;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Id;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

/**
 * 安鲜达 下单数据
 */
@Data
public class Jsp_axd_order
{

    @JsonIgnore
    @Id
    private String id;

    @JsonIgnore
    private String uuid;


    /**
     * 商户备注信息
     */
    @ApiModelProperty(value = "商户备注信息")
    private String partner_remark;

    /**
     * 商户订单号,要求唯一
     */
    @ApiModelProperty(value = "商户订单号,要求唯一")
    private String partner_order_code;


    /**
     * 取货点信息
     */
    @ApiModelProperty(value = "取货点信息")
    private transport_info transport_info;


    /**
     * 下单时间(毫秒)
     */
    @ApiModelProperty(value = "下单时间(毫秒)")
    private Long order_add_time;


    /**
     * 配送费
     */
    @ApiModelProperty(value = "配送费")
    private BigDecimal order_total_delivery_cost;


    /**
     * 订单总金额（不包含商家的任何活动以及折扣的金额）
     */
    @ApiModelProperty(value = "订单总金额")
    private BigDecimal order_total_amount;


    /**
     * 客户需要支付的金额
     */
    @ApiModelProperty(value = "客户需要支付的金额")
    private BigDecimal order_actual_amount;


    /**
     * 订单总重量（kg），营业类型选定为果蔬生鲜、商店超市、其他三类时必填，大于0kg并且小于等于6kg
     */
    @ApiModelProperty(value = "订单总重量")
    private BigDecimal order_weight;


    /**
     * 用户备注
     */
    @ApiModelProperty(value = "用户备注")
    private String order_remark;


    /**
     * 订单支付状态 0:未支付 1:已支付
     */
    @ApiModelProperty(value = "订单支付状态 0:未支付 1:已支付")
    private Integer order_payment_status;


    /**
     * 订单支付方式 1:在线支付
     */
    @ApiModelProperty(value = "订单支付方式")
    private Integer order_payment_method;


    /**
     * 订单货物件数
     */
    @ApiModelProperty(value = "订单货物件数")
    private Integer goods_count;

    /**
     * 需要送达时间（毫秒)
     */
    @ApiModelProperty(value = "需要送达时间（毫秒)")
    private Long require_receive_time;
    /**
     * 收件人信息
     */
    @ApiModelProperty(value = "收件人信息")
    private receiver_info receiver_info;

    /**
     * 商品信息
     */
    @ApiModelProperty(value = "商品信息")
    private List<items> items;

    /**
     * 商家订单流水号, 方便配送骑手到店取货, 支持数字,字母及#等常见字符. 如不填写, 安鲜达将截取商家订单号后4位作为流水号.
     */
    @ApiModelProperty(value = "商家订单流水号")
    private String serial_number;

    /**
     * 是否需要发票 0 不需要，1 需要
     */
    @ApiModelProperty(value = "是否需要发票 0 不需要，1 需要")
    private Integer isInvoice;

    /**
     * 发票抬头
     */
    @ApiModelProperty(value = "发票抬头")
    private String invoice_title;
    /**
     * 客户标识
     */
    @JsonIgnore
    private String ClientFlag;


    /**
     * 接受订单时间
     */
    @JsonInclude(NON_NULL)
    private String date;


    public Jsp_Order toJspOrder() {
        Jsp_Order j = new Jsp_Order();
        j.setOid(id);
        j.setOuuid(uuid);
        j.setDdzt("10");
        j.setGc(goods_count);
        j.setDate(date);
        j.setClientFlag(ClientFlag);
        j.setPr(partner_remark);
        j.setPoc(partner_order_code);
        j.setOta(order_total_amount);
        j.setOaa(order_actual_amount);
        j.setOr(order_remark);
        j.setOps(order_payment_status);
        j.setOpm(order_payment_method);

        j.setGc(goods_count);
        j.setRrt(require_receive_time);
        j.setOw(order_weight);
        j.setSn(serial_number);
        j.setOat(order_add_time);

        j.setIIn(isInvoice);
        j.setIt(invoice_title);
        j.setOdc(order_total_delivery_cost);

        // 取货点信息
        if (transport_info != null) {
            j.setFtn(transport_info.getTransport_name());
            j.setFps(transport_info.getPosition_source());
            j.setFta(transport_info.getTransport_address());
            j.setFtly(transport_info.getTransport_latitude());
            j.setFtlx(transport_info.getTransport_longitude());
            j.setFtt(transport_info.getTransport_tel());
            j.setMdbm(transport_info.getTransport_id());
        }

        // 收件人信息
        if (receiver_info != null) {
            j.setSrn(receiver_info.getReceiver_name());
            j.setSrpp(receiver_info.getReceiver_primary_phone());
            j.setSra(receiver_info.getReceiver_address());
            j.setSrly(receiver_info.getReceiver_latitude());
            j.setSrlx(receiver_info.getReceiver_longitude());
        }

        if (items != null) {
            List<Jsp_Items> jspItems = new ArrayList<>();
            for (com.zjs.jsp.domain.axd.items item : items) {
                jspItems.add(item.toJspItems());
            }
            j.setIs(jspItems);
        }

        j.setCancel(0);

        return j;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"id\":\"")
                .append(id).append('\"');
        sb.append(",\"uuid\":\"")
                .append(uuid).append('\"');
        sb.append(",\"partner_remark\":\"")
                .append(partner_remark).append('\"');
        sb.append(",\"partner_order_code\":\"")
                .append(partner_order_code).append('\"');
        sb.append(",\"transport_info\":")
                .append(transport_info);
        sb.append(",\"order_add_time\":")
                .append(order_add_time);
        sb.append(",\"order_total_delivery_cost\":")
                .append(order_total_delivery_cost);
        sb.append(",\"order_total_amount\":")
                .append(order_total_amount);
        sb.append(",\"order_actual_amount\":")
                .append(order_actual_amount);
        sb.append(",\"order_weight\":")
                .append(order_weight);
        sb.append(",\"order_remark\":\"")
                .append(order_remark).append('\"');
        sb.append(",\"order_payment_status\":")
                .append(order_payment_status);
        sb.append(",\"order_payment_method\":")
                .append(order_payment_method);
        sb.append(",\"goods_count\":")
                .append(goods_count);
        sb.append(",\"require_receive_time\":")
                .append(require_receive_time);
        sb.append(",\"receiver_info\":")
                .append(receiver_info);
        sb.append(",\"items\":")
                .append(items);
        sb.append(",\"serial_number\":\"")
                .append(serial_number).append('\"');
        sb.append(",\"isInvoice\":")
                .append(isInvoice);
        sb.append(",\"invoice_title\":\"")
                .append(invoice_title).append('\"');
        sb.append(",\"ClientFlag\":\"")
                .append(ClientFlag).append('\"');
        sb.append(",\"date\":\"")
                .append(date).append('\"');
        sb.append('}');
        return sb.toString();
    }
}